package cn.bigway.app.weavingdesigner.action.newdoc;

import cn.bigway.app.weavingdesigner.Resources;
import cn.bigway.app.weavingdesigner.main.WdMainFrame;
import cn.bigway.app.weavingdesigner.util.WdInputDialog;
import cn.bigway.app.weavingdesigner.util.WdIntTextField;
import cn.bigway.app.weavingdesigner.weaving.WdWeavingDoc;
import cn.bigway.app.weavingdesigner.weaving.WdWeavingDocFactory;
import cn.bigway.app.weavingdesigner.weaving.WdWeavingDocInitData;

public class WdNewDocDialog extends WdInputDialog {

	private static final long serialVersionUID = -478462311704720171L;

	WdIntTextField widthField, heightField, needleCountField;

	public WdNewDocDialog() {
		this.contentPanel.add(Resources.getLabel(Resources.LabelType.HIGTH));

		this.widthField = new WdIntTextField(10, 200, 1, 1000);
		this.contentPanel.add(this.widthField);
		this.heightField = new WdIntTextField(10, 200, 1, 1000);
		this.contentPanel.add(this.heightField);
		this.needleCountField = new WdIntTextField(4, 4, 1, 8);
		this.contentPanel.add(this.needleCountField);
	}

	@Override
	protected void submitPerformed() {
		WdWeavingDoc doc = WdWeavingDocFactory.getInstance().create(this);
		WdMainFrame.getInstance().addWeavingDoc(doc);
	}

	public WdWeavingDocInitData getData() {
		WdWeavingDocInitData data = new WdWeavingDocInitData();
		data.setWidth(this.widthField.getValue().intValue());
		data.setHeight(this.heightField.getValue().intValue());
		data.setNeedleCount(this.needleCountField.getValue().intValue());
		return data;
	}
}